import request from '@/utils/request';
import { ChannelType } from '@/store/reducers/channel';

/**
 * 获取所有频道列表
 * @returns {Promise} Promise<void>
 */
export const getChannelsAPI = () => {
  return request({
    url: '/v1_0/channels',
  });
};

/**
 * 获取用户频道列表
 * @returns {Promise} Promise<void>
 */
export const getUserChannelAPI = () => {
  return request({
    url: '/v1_0/user/channels',
  });
};

/**
 * 删除指定用户频道
 * @returns {Promise} Promise<void>
 */
export const delUserChannelByIdAPI = (id: number) => {
  return request({
    url: '/v1_0/user/channels/' + id,
    method: 'DELETE',
  });
};

/**
 * 设置用户的频道（部分覆盖）
 * @returns {Promise} Promise<void>
 */
export const addUserChannelByIdAPI = (channelList: ChannelType[]) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PATCH',
    data: {
      channels: channelList,
    },
  });
};
